#ifndef BASICS_VECTOR
#define BASICS_VECTOR
//#include "stdafx.h"
using namespace std;
 class Basics_vector
{
public:
	template <class T> static T maxval(vector<T> &val)
	{
		unsigned int row;
		T a;
		for(row=0;row<val.size();row++)
		{
			if (row==0) a=val[row];
			else{
				if (a<val[row]) a=val[row];
			}
		}
			return a;
	}
	template <class T> static unsigned int minvalpos(vector<T> &val)
	{
		unsigned int row;
		int rowid;
		T a;
		rowid=0;
		for(row=0;row<val.size();row++)
		{
			if (row==0) 
			{
				a=val[row];
				rowid=row;
			}
			else{
				if (a>val[row])
				{
						a=val[row];
						rowid=row;
				}
			}
		}
		return rowid;
	}
    template <class T> static int find_position_of_object(vector <T> &val, T x)
        {
            unsigned int row;

            for(row=0;row<val.size();row++)
            {
                if (val[row]==x) return row;
            }
            return val.size();
        }
    template <class T> static int check_for_similarities(vector <T> &val)
        {
            
            int count;
            unsigned int row,row1;
            for(row=0;row<val.size();row++)
            {
                count=0;
                for(row1=0;row1<val.size();row1++)
                {
                    count=count+(val[row]==val[row1]);
                }
                if (count>1) return 1;
            }
            return 0;
        }
   
    template <class T> static int find_successor_pos_in_ordered_vector(vector<T> source,T &val)
        {
            //function delivers precursor or equal value
            int row;
            if (source.size()==0) return 0;
            if (source.size()==1) {
				if ((source[0]>val)) return 0;
				else return source.size();
			}
            for(row=source.size()-1;row>0;row--)
            {
                if ((source[row]>val)&&(val>source[row-1])) return row;
                if ((source[row]==val)&&(val>source[row-1])) return row;
            }
            if (source[0]>=val) return 0;
            err::err2("Basics_vector::find_successor_in_ordered_vector: object is not coverered by vector values");
            return source.size();
        }
      template <class T> static int find_successor_pos_in_ordered_vector(vector<T> source,const T &val)
        {
            //function delivers precursor or equal value
            int row;
            if (source.size()==0) return 0;
            if (source.size()==1) {
				if ((source[0]>val)) return 0;
				else return source.size();
			}
            for(row=source.size()-1;row>0;row--)
            {
                if ((source[row]>val)&&(val>source[row-1])) return row;
                if ((source[row]==val)&&(val>source[row-1])) return row;
            }
            if (source[0]>=val) return 0;
            err::err2("Basics_vector::find_successor_in_ordered_vector: object is not coverered by vector values");
            return source.size();
        }
           
    template <class T>static int find_precursor_pos_in_ordered_vector(vector<T> &source,T &val)
        {
            unsigned int row;
            if (source.size()==0) return 0;
            if (source.size()==1){
				if((source[0]<=val)) return 0;
				else return source.size();
			}
            for(row=1;row<source.size();row++)
            {
                if ((source[row-1]<val)&&(source[row]>val)) return row-1;
                if ((source[row-1]==val)&&(source[row]>val)) return row-1;
            }
            if (source[source.size()-1]<=val) return source.size()-1;
            err::err2("Basics_vector::find_precursor_in_ordered_vector: object is not coverered by vector values");
            return source.size();
        }
     template <class T>static int find_precursor_pos_in_ordered_vector(vector<T> &source,const T &val)
        {
            unsigned int row;
            if (source.size()==0) return 0;
            if (source.size()==1){
				if((source[0]<=val)) return 0;
				else return source.size();
			}
            for(row=1;row<source.size();row++)
            {
                if ((source[row-1]<val)&&(source[row]>val)) return row-1;
                if ((source[row-1]==val)&&(source[row]>val)) return row-1;
            }
            if (source[source.size()-1]<=val) return source.size()-1;
            err::err2("Basics_vector::find_precursor_in_ordered_vector: object is not coverered by vector values");
            return source.size();
        }
      template <class T > static int find_precursor_pos_in_ordered_vector(vector < T > *source,T &val)
        {
            unsigned int row;
            if (source->size()==0) return 0;
            if (source->size()==1){
				if((source->at(0)<=val)) return 0;
				else return source->size();
			}
            for(row=1;row<source->size();row++)
            {
                if ((source->at(row-1)<val)&&(source->at(row)>val)) return row-1;
                if ((source->at(row-1)==val)&&(source->at(row)>val)) return row-1;
            }
            if (source->at(source->size()-1)=val) return source->size()-1;
            err::err2("Basics_vector::find_precursor_in_ordered_vector: object is not coverered by vector values");
            return source->size();
        }
     template <class T> static T find_precursor_in_ordered_vector(vector<T> source,T &val)
        {
            //function delivers precursor or equal value
            unsigned int row;
            row=Basics_vector::find_precursor_pos_in_ordered_vector(source,val);
            
            if(row==source.size()) {
				 err::err3("Basics_vector::find_precursor_in_ordered_vector: object is not coverered by vector values");
				 return source[0];
			}
            else return source[row];
        }
    template <class T> static T find_successor_in_ordered_vector(vector<T> source,T &val)
        {
            //function delivers precursor or equal value
                        //function delivers precursor or equal value
            unsigned int row;
            row=Basics_vector::find_successor_pos_in_ordered_vector(source,val);
            
            if(row==source.size()) {
				 err::err3("Basics_vector::find_successor_in_ordered_vector: object is not coverered by vector values");
				 return source[0];
			}
            else return source[row];
        }
	template <class T>static int check_for_ascending_order(vector <T> &val){
			unsigned int row;
			if(val.size()==0) return 0;
			for (row=1;row<val.size();row++)
			{
				if(val[row-1]>val[row]) {
				return 1;	}
			}
			return 0;
		}
	template <class T> static int count (const vector <T> &val,const unsigned int a, const unsigned int b, const T &ref){
			unsigned int row;
			int count=0;
			if ((val.size()<b)||(b<=a)) err::err3("Basics_Vector::count: the upper intervallindice is out of range");
			if ((a<0)||(a>=b)) err::err3("Basics_Vector::count: the lower intervallindice is bigger than vector_size");
			if (val.size()<=0) err::err3("Basics_Vector::count: Source_vector is ZERO");
			for(row=a;row<b;row++){
				if(ref==val[row]) count++;
			}
			return count;
		}

	// Vector operations
	template<class T> static int push_back_vector( vector<T> &a,const vector<T> &b)
	{
		int row;
		for (row=0;row<b.size();row++){
			a.push_back(b[row]);
		}
		return a;
	}
	 template<class T> static int push_back_vector( vector<T> *a,const vector <T> *b)
	 {
		unsigned int row;
		for (row=0;row<b->size();row++){
			   a->push_back(b->at(row));
		}
		return 0;
	 }
};

#endif

